package com.wjv.example.springboot.base.dao;

import com.wjv.example.springboot.base.entity.UserInfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * <p>Title: UserInfoDAO</p>
 *
 * @author wjv
 * @date Create in 2021/3/18 16:04
 * @description
 */
@Repository
public class UserInfoDAO {

    @Autowired
    private NamedParameterJdbcTemplate jdbcTemplate;

    public UserInfoEntity getUserInfo(int id) {
        String sql = "select * FROM user_info where id = :id ";

        MapSqlParameterSource msp = new MapSqlParameterSource();
        msp.addValue("id", id);

        return jdbcTemplate.queryForObject(sql, msp, new BeanPropertyRowMapper<>(UserInfoEntity.class));
    }
}
